#include "maininterface.h"
#include "ui_maininterface.h"
#include <QMessageBox>
#include"warninginformation.h"
#include "sensorthresholdparametersset.h"
#include"monitordevice.h"
#include "alarmalerttone.h"
#include"manualcontrol.h"
#include"pidparameterset.h"
#include"pidcontroller.h"
#include"logrecord.h"
Q_GLOBAL_STATIC(MainInterface,theInstance);
MainInterface::MainInterface(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainInterface)
{
    ui->setupUi(this);
   initModSimProcess();
    this->setWindowTitle("蔬菜大棚物联网测量与控制系统主界面");
    this->setWindowIcon(QIcon(":res/res/Main_Interface.ico"));

    setPushButtonStyleSheet();
    ui->pushButtonMainSwitch->setEnabled(false);
    connect(SerialPortSet::instance(),&SerialPortSet::sendMainSwitchEnabel,this,[&](){
        ui->pushButtonMainSwitch->setEnabled(true);
    });
    connect(this,&MainInterface::sendMainSwitchEnabel,this,[&](){
        ui->pushButtonMainSwitch->setEnabled(true);
    });

    connect(MainWindow::instance(),&MainWindow::sendUpDateUserInformation,this,[&](){
        extern UserInfo currentUserInfo;
        ui->labelCurrentUserName->setText(currentUserInfo.userName);
        if(currentUserInfo.userType)
        {
          ui->labelCurrentUserType->setText("管理员");
          ui->userListPushButton_S->setEnabled(true);
        }else{
          ui->labelCurrentUserType->setText("用户");
          ui->userListPushButton_S->setEnabled(false);
        }
    });
    initRadioPushbutton();

    initdeviceStatusDataBlock();//初始化各设备状态

    initCtrlMode();//初始化控制模式
    MonitorDevice::instance();//初始化传感器报警阈值
    // connect(ui->pushButton_Back, &QPushButton::clicked, this, &MainInterface::returnToParent);
    //connectSerialPort();//重要
   // initWarningLight();
    initQStatusBar();
    i=0;
//    qTiemrDisplayData();
    initDeviceStatusLED();
    initWarningSmallLED(smallLED);
    //setPushbuttonStatus();
    linkingDevice();//设备串口连接---------------
    setMainSwitchStatus();//设置主开关的状态显示
    setQlcdNumberColor();//设置lcd显示颜色
    setPidQlcdNumberColor();

    qTiemrDisplayData();
    //初始化系统警报音


    connect(this,&MainInterface::sendMosimDeviceSwitchStatus,DeviceSerialportControl::instance(),&DeviceSerialportControl::QTimerReadModsimData,Qt::DirectConnection);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::mainSwitch_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::IrrigationEquipment_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::ventilatingEquipment_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::CO2Interpolator_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::rollUpDoor_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::lightingEquipment_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::heatingEquipment_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::airCooler_LEDChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(DeviceSerialportControl::instance(),&DeviceSerialportControl::warningLedChanged,this,&MainInterface::refreshDeviceStatusLEDONorOff);
    connect(MonitorDevice::instance(),&MonitorDevice::sendAirTemperature,this,&MainInterface::warningAirTLED);
    connect(MonitorDevice::instance(),&MonitorDevice::sendAirHumidity,this,&MainInterface::warningAirHLED);
    connect(MonitorDevice::instance(),&MonitorDevice::sendLightIntensity,this,&MainInterface::warningLightLED);
    connect(MonitorDevice::instance(),&MonitorDevice::sendCO2Concentration,this,&MainInterface::warningCO2LED);
    connect(MonitorDevice::instance(),&MonitorDevice::sendSoilMoisture,this,&MainInterface::warningSoilHLED);
    connect(MonitorDevice::instance(),&MonitorDevice::sendWarningLed,this,&MainInterface::warningLed);
    //自动控制
    initAutoTimer();
    initSelectIrrAndVan();//初始化灌溉和通风设备选择
    connect(UserMysqlS::instance(),&UserMysqlS::sendPidSetPointValueChanged,this,&MainInterface::setPidSetPointValue);//更新Pid SV值

    connect(PidController::instance(),&PidController::sendAutoControlAirTemperatureLED,this,&MainInterface::autoControlAirTemperatureDeviceLED);
    connect(AutoTimer[0],&QTimer::timeout,this,&MainInterface::closeAirTemperatureDeviceLED);
    connect(PidController::instance(),&PidController::sendCloseControlAirTemperatureLEDNormal,this,&MainInterface::closeAirTemperatureDeviceLEDNormal);

    connect(PidController::instance(),&PidController::sendAutoControlAirHumidityLED,this,&MainInterface::autoControlAirHumidityDeviceLED);
    connect(AutoTimer[1],&QTimer::timeout,this,&MainInterface::closeAirHumidityDeviceLED);
    connect(PidController::instance(),&PidController::sendCloseControlAirHumidityLEDNormal,this,&MainInterface::closeAirHumidityDeviceLEDNormal);

    connect(PidController::instance(),&PidController::sendAutoControlLightIntensityLED,this,&MainInterface::autoControlLightIntensityDeviceLED);
    connect(AutoTimer[2],&QTimer::timeout,this,&MainInterface::closeLightIntensityDeviceLED);
    connect(PidController::instance(),&PidController::sendCloseControlLightIntensityLEDNormal,this,&MainInterface::closeLightIntensityDeviceLEDNormal);

    connect(PidController::instance(),&PidController::sendAutoControlCO2ConcentrationLED,this,&MainInterface::autoControlCO2ConcentrationDeviceLED);
    connect(AutoTimer[3],&QTimer::timeout,this,&MainInterface::closeCO2ConcentrationDeviceLED);
    connect(PidController::instance(),&PidController::sendCloseControlCO2ConcentrationLEDNormal,this,&MainInterface::closeCO2ConcentrationDeviceLEDNormal);

    connect(PidController::instance(),&PidController::sendAutoControlSoilMoistureLED,this,&MainInterface::autoControlSoilMoistureDeviceLED);
    connect(AutoTimer[4],&QTimer::timeout,this,&MainInterface::closeSoilMoistureDeviceLED);
    connect(PidController::instance(),&PidController::sendCloseControlSoilMoistureLEDNormal,this,&MainInterface::closeSoilMoistureDeviceLEDNormal);

}

MainInterface::~MainInterface()
{
    delete ui;
}

MainInterface *MainInterface::instance()
{
    return theInstance;
}

void MainInterface::on_pushButton_Back_clicked()
{

    returnToParent();



}

void MainInterface::returnToParent()
{
    this->close(); // 关闭子窗口
    //    MainWindow *view=new MainWindow();
    //    view->show();
    MainWindow::instance()->show();//返回登录页面
}

void MainInterface::connectSerialPort(bool status )
{
    extern bool SerialPortConnectStatus;


    //SerialPortConnection::instance()->readModsimData();
    int size=0;
    sensorData data;
    // size=ModBusManger::instance()->getSensorDataSet().size();
    //ModBusManger::instance()->getSensorDataSet();
    if(status)
    {
        bool modBusDeviceStatus=ModBusManger::instance()->getModBusDeviceStatus();//0表示没有连接 1表示连接

        if(!modBusDeviceStatus)
        {

            ModBusManger::instance()->reConnectDevice();

        }

    }
    else
    {
        bool modBusDeviceStatus=ModBusManger::instance()->getModBusDeviceStatus();
        if(modBusDeviceStatus)
        {
            ModBusManger::instance()->disConnectDevice();


        }
    }




}

void MainInterface::initWarningLight()
{
    //    ui->warningLed->clear();//清空led中的内容
    //    //初始化灯为绿灯
    //    isNormal=1;//1为正常0为异常
    //    //设置警报灯的大小
    //    ui->warningLed->setFixedSize(QSize(50,50));//将灯设置为x为50,y为50像素

    //    //设置警报灯初始为绿灯
    //    QString style = "QLabel {"
    //                    "background-color: %1;"
    //                    "border-radius: 25px;"
    //                    "border: 2px solid black;"
    //                    "}";


    //    ui->warningLed->setStyleSheet(style.arg(isNormal ? "#00FF00"  : "#FF0000"  ));// 正常状态：绿色// 异常状态：红色




}

void MainInterface::initDeviceStatusLED()
{


    //清空内容
    ui->mainSwitch_LED->clear();
    ui->IrrigationEquipment_LED->clear();
    ui->ventilatingEquipment_LED->clear();
    ui->CO2Interpolator_LED->clear();
    ui->rollUpDoor_LED->clear();
    ui->lightingEquipment_LED->clear();
    ui->heatingEquipment_LED->clear();
    ui->airCooler_LED->clear();
    ui->warningLed->clear();

    //    //设置警报灯初始为绿灯
    //    QString style = "QLabel {"
    //                    "background-color: %1;"
    //                    "border-radius: 25px;"
    //                    "border: 2px solid black;"
    //                    "}";
    ui->mainSwitch_LED->setFixedSize(QSize(50,50));
    ui->IrrigationEquipment_LED->setFixedSize(QSize(50,50));
    ui->ventilatingEquipment_LED->setFixedSize(QSize(50,50));
    ui->CO2Interpolator_LED->setFixedSize(QSize(50,50));
    ui->rollUpDoor_LED->setFixedSize(QSize(50,50));
    ui->lightingEquipment_LED->setFixedSize(QSize(50,50));
    ui->heatingEquipment_LED->setFixedSize(QSize(50,50));
    ui->airCooler_LED->setFixedSize(QSize(50,50));
    ui->warningLed->setFixedSize(QSize(50,50));
    //    QString green="#00FF00";
    //    ui->mainSwitch_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->IrrigationEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->ventilatingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->CO2Interpolator_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->rollUpDoor_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->lightingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->heatingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
    //    ui->airCooler_LED->setStyleSheet(style.arg("#00FF00" ));
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    setDeviceStatusLEDONorOff(DeviceStatusDataBlock);



}

void MainInterface::initQStatusBar()
{


    ui->statusbar->addWidget(ui->pushButtonHistoryData);//历史数据

    ui->statusbar->addWidget(ui->pidParameterSetPushbutton_S);//pid控制参数设置
    ui->statusbar->addWidget(ui->logPushbutton_S);//运行记录
    ui->statusbar->addWidget(ui->dynamicCurvePushButton_S);//动态曲线
    ui->statusbar->addWidget(ui->warningPushButton_S);//报警信息
    ui->statusbar->addWidget(ui->timePushButton_S);//时间设置
    ui->statusbar->addWidget(ui->parameterSetingPushButton_S);//参数设置
    ui->statusbar->addWidget(ui->userListPushButton_S);//用户名单
    ui->statusbar->addWidget(ui->SQLPushButton_S);//添加数据库按钮
    ui->statusbar->addWidget(ui->switchUserPushButton_S);//切换用户
   // ui->statusbar->addWidget(ui->changePssswordPushButton_S);//修改密码
    ui->statusbar->addWidget(ui->pushButtonModsimDeviceSwitch);//modsim设备开关
    ui->statusbar->addWidget(ui->ModSim32PushButton_S);//增加Modsim32设备的打开开关
    ui->statusbar->addWidget(ui->pushButton_Back);//返回登录界面
    ui->statusbar->addWidget(ui->logOutPushButton_S);//退出系统

}

void MainInterface::setPushbuttonStatus()
{   /*mainSwitchStatus=false;
    ui->pushButtonMainSwitch->setCheckable(true);
    ui->pushButtonMainSwitch->setChecked(mainSwitchStatus);*/





}

void MainInterface::initdeviceStatusDataBlock()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    extern bool MainSwitch;
    DeviceStatusDataBlock.mainSwitch_LED=MainSwitch;//主开关
    DeviceStatusDataBlock.IrrigationEquipment_LED=false;//灌溉设备;
    DeviceStatusDataBlock.ventilatingEquipment_LED=false;//通风设备
    DeviceStatusDataBlock.CO2Interpolator_LED=false;
    DeviceStatusDataBlock.rollUpDoor_LED=false;
    DeviceStatusDataBlock.lightingEquipment_LED=false;
    DeviceStatusDataBlock.heatingEquipment_LED=false;
    DeviceStatusDataBlock.airCooler_LED=false;
    DeviceStatusDataBlock.warningLed=true;
    ui->pushButtonMainSwitch->setCheckable(true);
    ui->pushButtonMainSwitch->setChecked(MainSwitch);



}

void MainInterface::initCtrlMode()
{
    extern bool AutoControlStatus;
    extern bool AutoControlStatus2;
    extern bool AutoControlStatus3;
    ctrlMode=true;//0为手动1为自动
    AutoControlStatus=true;
    AutoControlStatus2=AutoControlStatus;
    AutoControlStatus3=AutoControlStatus;
    ui->CtrlMode->setCurrentIndex(ctrlMode);

}


void MainInterface::on_pushButton_12_clicked()
{

    extern QVector<sensorData>globalSensorData;
    //globalSensorData;
    int count=globalSensorData.size();

//    QString str=QString::number(count);
//    int Temp=globalSensorData.end()->AirHumidity;
    //ui->lcdNumberCO2->setDecMode();
//    ui->testLabel->setText(str);
//    for(QVector<sensorData>::Iterator it=globalSensorData.begin();it<globalSensorData.begin()+10;it++)
//    {
//        Temp=it->AirHumidity;

//        ui->lcdNumberCO2->display(Temp);
//    }
    ui->lcdNumberCurrentDataCount->display(count);


}
//void test()
//{
//    QButtonGroup a;
//}

void MainInterface::qTiemrDisplayData()
{

    if(1){
        // 启动定时轮询（首次立即执行，后续每3秒一次）
        QTimer::singleShot(0, this, &MainInterface::LcdNumberDispaly);
        m_timer_View = new QTimer(this);
        connect(m_timer_View, &QTimer::timeout, this,&MainInterface:: LcdNumberDispaly);
        m_timer_View->start(1000); // 1秒间隔



    }





}

void MainInterface::LcdNumberDispaly()
{

    //extern QVector<sensorData>::Iterator totalIt;
    extern QVector<sensorData>globalSensorData;
    extern int totalCount;

    i=totalCount-1;
    if(totalCount>=1)
    {
        ui->lcdNumberCO2->display(globalSensorData[i].CO2Concentration);
        ui->lcdNumberLight->display(globalSensorData[i].LightIntensity);
        ui->lcdNumberAirT->display(globalSensorData[i].AirTemperature);
        ui->lcdNumberAirH->display(globalSensorData[i].AirHumidity);
        ui->lcdNumberSoil->display(globalSensorData[i].SoilMoisture);
        ui->lcdNumberTime->setDigitCount(20);
        ui->lcdNumberTime->display(globalSensorData[i].Time);

        ui->lcdNumberPidAirT_PV->display(globalSensorData[i].AirTemperature);
        ui->lcdNumberPidAirH_PV->display(globalSensorData[i].AirHumidity);
        ui->lcdNumberPidLight_PV->display(globalSensorData[i].LightIntensity);
        ui->lcdNumberPidCO2_PV->display(globalSensorData[i].CO2Concentration);
        ui->lcdNumberPidSoilH_PV->display(globalSensorData[i].SoilMoisture);
    }


}






void MainInterface::initRadioPushbutton()
{
    QButtonGroup *G1=new QButtonGroup(this);
    QButtonGroup *G2=new QButtonGroup(this);
    QButtonGroup *G3=new QButtonGroup(this);
    QButtonGroup *G4=new QButtonGroup(this);
    QButtonGroup *G5=new QButtonGroup(this);
    QButtonGroup *G6=new QButtonGroup(this);
    QButtonGroup *G7=new QButtonGroup(this);
    G1->addButton(ui->radioButtonG1_1);
    G1->addButton(ui->radioButtonG1_2);
    G2->addButton(ui->radioButtonG2_1);
    G2->addButton(ui->radioButtonG2_2);
    G3->addButton(ui->radioButtonG3_1);
    G3->addButton(ui->radioButtonG3_2);
    G4->addButton(ui->radioButtonG4_1);
    G4->addButton(ui->radioButtonG4_2);
    G5->addButton(ui->radioButtonG5_1);
    G5->addButton(ui->radioButtonG5_2);
    G6->addButton(ui->radioButtonG6_1);
    G6->addButton(ui->radioButtonG6_2);
    G7->addButton(ui->radioButtonG7_1);
    G7->addButton(ui->radioButtonG7_2);
    //setRadioCheckabel(!ctrlMode);
    setRadioCheckabel(false);//初始化
}

void MainInterface::setRadioCheckabel(bool CtrlMode)
{



    ui->radioButtonG1_1->setCheckable(CtrlMode);
    ui->radioButtonG1_2->setCheckable(CtrlMode);
    ui->radioButtonG2_1->setCheckable(CtrlMode);
    ui->radioButtonG2_2->setCheckable(CtrlMode);
    ui->radioButtonG3_1->setCheckable(CtrlMode);
    ui->radioButtonG3_2->setCheckable(CtrlMode);
    ui->radioButtonG4_1->setCheckable(CtrlMode);
    ui->radioButtonG4_2->setCheckable(CtrlMode);
    ui->radioButtonG5_1->setCheckable(CtrlMode);
    ui->radioButtonG5_2->setCheckable(CtrlMode);
    ui->radioButtonG6_1->setCheckable(CtrlMode);
    ui->radioButtonG6_2->setCheckable(CtrlMode);
    ui->radioButtonG7_1->setCheckable(CtrlMode);
    ui->radioButtonG7_2->setCheckable(CtrlMode);









}

void MainInterface::setDeviceStatusLEDONorOff(deviceStatusDataBlock &Data,int index,bool ok)
{


    QString style = "QLabel {"
                    "background-color: %1;"
                    "border-radius: 25px;"
                    "border: 2px solid white;"
                    "}";
    if(ok){
        if(Data.mainSwitch_LED)
        {
            ui->mainSwitch_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->mainSwitch_LED->setStyleSheet(style.arg("#03551a" ));
        }
        if(Data.IrrigationEquipment_LED)
        {
            ui->IrrigationEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->IrrigationEquipment_LED->setStyleSheet(style.arg("#03551a" ));
        }
        if(Data.ventilatingEquipment_LED)
        {
            ui->ventilatingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->ventilatingEquipment_LED->setStyleSheet(style.arg("#03551a" ));
        }

        if(Data.CO2Interpolator_LED)
        {
            ui->CO2Interpolator_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->CO2Interpolator_LED->setStyleSheet(style.arg("#03551a" ));
        }
        if(Data.rollUpDoor_LED)
        {
            ui->rollUpDoor_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->rollUpDoor_LED->setStyleSheet(style.arg("#03551a" ));
        }
        if(Data.lightingEquipment_LED)
        {
            ui->lightingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->lightingEquipment_LED->setStyleSheet(style.arg("#03551a"));
        }
        if(Data.heatingEquipment_LED)
        {
            ui->heatingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->heatingEquipment_LED->setStyleSheet(style.arg("#03551a"));
        }


        if(Data.airCooler_LED)
        {
            ui->airCooler_LED->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->airCooler_LED->setStyleSheet(style.arg("#03551a" ));
        }
        if(Data.warningLed)
        {
            ui->warningLed->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->warningLed->setStyleSheet(style.arg("#FF0000" ));
        }

    }
    else{
        switch(index)
        {
        case 0:

            if(Data.mainSwitch_LED)
            {
                ui->mainSwitch_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->mainSwitch_LED->setStyleSheet(style.arg("#03551a" ));
            }

            break;
        case 1:
            if(Data.IrrigationEquipment_LED)
            {
                ui->IrrigationEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->IrrigationEquipment_LED->setStyleSheet(style.arg("#03551a" ));
            }
            break;
        case 2:
            if(Data.ventilatingEquipment_LED)
            {
                ui->ventilatingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->ventilatingEquipment_LED->setStyleSheet(style.arg("#03551a" ));
            }
            break;
        case 3:
            if(Data.CO2Interpolator_LED)
            {
                ui->CO2Interpolator_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->CO2Interpolator_LED->setStyleSheet(style.arg("#03551a" ));
            }
            break;
        case 4:
            if(Data.rollUpDoor_LED)
            {
                ui->rollUpDoor_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->rollUpDoor_LED->setStyleSheet(style.arg("#03551a" ));
            }
            break;
        case 5:
            if(Data.lightingEquipment_LED)
            {
                ui->lightingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->lightingEquipment_LED->setStyleSheet(style.arg("#03551a"));
            }
            break;
        case 6:
            if(Data.heatingEquipment_LED)
            {
                ui->heatingEquipment_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->heatingEquipment_LED->setStyleSheet(style.arg("#03551a"));
            }
            break;
        case 7:
            if(Data.airCooler_LED)
            {
                ui->airCooler_LED->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->airCooler_LED->setStyleSheet(style.arg("#03551a" ));
            }
            break;
        case 8:
            if(Data.warningLed)
            {
                ui->warningLed->setStyleSheet(style.arg("#00FF00" ));//绿灯
            }
            else
            {
                ui->warningLed->setStyleSheet(style.arg("#FF0000" ));
            }
            break;


        }








    }
















}

void MainInterface::setDeviceStatusDataBlock(bool ok)
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    DeviceStatusDataBlock.IrrigationEquipment_LED=ok;//灌溉设备;
    DeviceStatusDataBlock.ventilatingEquipment_LED=ok;//通风设备
    DeviceStatusDataBlock.CO2Interpolator_LED=ok;
    DeviceStatusDataBlock.rollUpDoor_LED=ok;
    DeviceStatusDataBlock.lightingEquipment_LED=ok;
    DeviceStatusDataBlock.heatingEquipment_LED=ok;
    DeviceStatusDataBlock.airCooler_LED=ok;
}

void MainInterface::turnOffDeviceDisplay()
{
    //关闭标签显示
    ui->labelG1->setText("设备关闭");
    ui->labelG1->setText("设备关闭");
    ui->labelG1->setText("设备关闭");
    ui->labelG1->setText("设备关闭");
    ui->labelG1->setText("设备关闭");
    ui->labelG1->setText("设备关闭");
    ui->labelG1->setText("设备关闭");

    //使按钮失效
    setRadioCheckabel(false);
















}

void MainInterface::initWarningSmallLED(warningSmallLED &smallLED)
{


ui->warningLedAirT->clear();
ui->warningLedAirH->clear();
ui->warningLedCO2->clear();
ui->warningLedLight->clear();
ui->warningLedSoilH->clear();
ui->warningLedAirT->setFixedSize(QSize(20,20));
ui->warningLedAirH->setFixedSize(QSize(20,20));
ui->warningLedCO2->setFixedSize(QSize(20,20));
ui->warningLedLight->setFixedSize(QSize(20,20));
ui->warningLedSoilH->setFixedSize(QSize(20,20));
smallLED.warning_AirT=true;
smallLED.warning_AirH=true;
smallLED.warning_CO2=true;
smallLED.warning_Light=true;
smallLED.warning_SoilH=true;
setWarningSmallLEDStatus(smallLED);

}

void MainInterface::setWarningSmallLEDStatus(warningSmallLED &smallLED, int index, bool ok)
{

    QString style = "QLabel {"
                    "background-color: %1;"
                    "border-radius: 25px;"
                    "border: 2px solid white;"
                    "}";
    if(ok)
    {

        if(smallLED.warning_AirT)
        {
            ui->warningLedAirT->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->warningLedAirT->setStyleSheet(style.arg("#FF0000" ));
        }
        if(smallLED.warning_AirH)
        {
            ui->warningLedAirH->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->warningLedAirH->setStyleSheet(style.arg("#FF0000" ));
        }
        if(smallLED.warning_Light)
        {
            ui->warningLedLight->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->warningLedLight->setStyleSheet(style.arg("#FF0000" ));
        }

        if(smallLED.warning_CO2)
        {
            ui->warningLedCO2->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->warningLedCO2->setStyleSheet(style.arg("#FF0000" ));
        }
        if(smallLED.warning_SoilH)
        {
            ui->warningLedSoilH->setStyleSheet(style.arg("#00FF00" ));
        }
        else
        {
            ui->warningLedSoilH->setStyleSheet(style.arg("#FF0000" ));
        }

    }
    else{

        switch(index)
        {

        case 0:
            if(smallLED.warning_AirT)
            {
                ui->warningLedAirT->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->warningLedAirT->setStyleSheet(style.arg("#FF0000" ));
            }
            break;
        case 1:
            if(smallLED.warning_AirH)
            {
                ui->warningLedAirH->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->warningLedAirH->setStyleSheet(style.arg("#FF0000" ));
            }
            break;
        case 2:
            if(smallLED.warning_Light)
            {
                ui->warningLedLight->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->warningLedLight->setStyleSheet(style.arg("#FF0000" ));
            }

            break;
        case 3:
            if(smallLED.warning_CO2)
            {
                ui->warningLedCO2->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->warningLedCO2->setStyleSheet(style.arg("#FF0000" ));
            }
            break;
        case 4:
            if(smallLED.warning_SoilH)
            {
                ui->warningLedSoilH->setStyleSheet(style.arg("#00FF00" ));
            }
            else
            {
                ui->warningLedSoilH->setStyleSheet(style.arg("#FF0000" ));
            }
            break;

        }
    }






}

void MainInterface::initAutoTimer()
{
AutoTimer[0]=new QTimer(this);
AutoTimer[0]->setSingleShot(true);//单次触发.....................5.6----->  todo

AutoTimer[1]=new QTimer(this);
AutoTimer[1]->setSingleShot(false);//单次触发

AutoTimer[2]=new QTimer(this);
AutoTimer[2]->setSingleShot(false);//单次触发

AutoTimer[3]=new QTimer(this);
AutoTimer[3]->setSingleShot(false);//单次触发

AutoTimer[4]=new QTimer(this);
AutoTimer[4]->setSingleShot(false);//单次触发
}

void MainInterface::initSelectIrrAndVan()
{
ui->comboBoxIrrigationSelection->setCurrentIndex(2);
ui->comboBoxVentilationSelection->setCurrentIndex(3);
}

void MainInterface::setPidSetPointValue(int id)
{
    extern QVector<int>SetPointValueS;
    if(id==-1)
    {

        ui->lcdNumberPidAirT_SV->display(SetPointValueS[0]);
        ui->lcdNumberPidAirH_SV->display(SetPointValueS[1]);
        ui->lcdNumberPidLight_SV->display(SetPointValueS[2]);
        ui->lcdNumberPidCO2_SV->display(SetPointValueS[3]);
        ui->lcdNumberPidSoilH_SV->display(SetPointValueS[4]);

    }
    else{

        switch(id)
        {

        case 0:
            ui->lcdNumberPidAirT_SV->display(SetPointValueS[0]);
            break;
        case 1:
            ui->lcdNumberPidAirH_SV->display(SetPointValueS[1]);
            break;
        case 2:
            ui->lcdNumberPidLight_SV->display(SetPointValueS[2]);
            break;
        case 3:
            ui->lcdNumberPidCO2_SV->display(SetPointValueS[3]);
            break;
        case 4:
            ui->lcdNumberPidSoilH_SV->display(SetPointValueS[4]);
            break;

        }



    }

}

void MainInterface::setQlcdNumberColor(int index,bool status,bool set)
{
    QString style="QLCDNumber {"
                  "   color: rgb(0, 255, 0);"          // 数字颜色
                  "   background-color: black;" // 背景颜色
                  "}";
    QString style2="QLCDNumber {"
                  "   color: rgb(255, 0, 0);"          // 数字颜色
                  "   background-color: black;" // 背景颜色
                  "}";
    if(set)
    {
        ui->lcdNumberCO2->setStyleSheet(style);
        ui->lcdNumberCO2->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
        ui->lcdNumberAirT->setStyleSheet(style);
        ui->lcdNumberAirT->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
        ui->lcdNumberAirH->setStyleSheet(style);
        ui->lcdNumberAirH->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
        ui->lcdNumberLight->setStyleSheet(style);
        ui->lcdNumberLight->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
        ui->lcdNumberSoil->setStyleSheet(style);
        ui->lcdNumberSoil->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
    }
    else{
         switch(index)
         {
         case 0:
             if(status){
                 ui->lcdNumberAirT->setStyleSheet(style);
                 ui->lcdNumberAirT->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
             }
             else
             {
                 ui->lcdNumberAirT->setStyleSheet(style2);
                 ui->lcdNumberAirT->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效

             }

         break;
         case 1:
             if(status){
                 ui->lcdNumberAirH->setStyleSheet(style);
                 ui->lcdNumberAirH->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
             }
             else
             {
                 ui->lcdNumberAirH->setStyleSheet(style2);
                 ui->lcdNumberAirH->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效

             }
         break;
         case 2:
             if(status){
                 ui->lcdNumberLight->setStyleSheet(style);
                 ui->lcdNumberLight->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
             }
             else
             {
                 ui->lcdNumberLight->setStyleSheet(style2);
                 ui->lcdNumberLight->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效

             }

         break;
         case 3:
             if(status){
                 ui->lcdNumberCO2->setStyleSheet(style);
                 ui->lcdNumberCO2->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
             }
             else
             {
                 ui->lcdNumberCO2->setStyleSheet(style2);
                 ui->lcdNumberCO2->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效

             }

         break;
         case 4:
             if(status){
                 ui->lcdNumberSoil->setStyleSheet(style);
                 ui->lcdNumberSoil->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效
             }
             else
             {
                 ui->lcdNumberSoil->setStyleSheet(style2);
                 ui->lcdNumberSoil->setSegmentStyle(QLCDNumber::Flat); // 确保颜色生效

             }

         break;
         }




    }

}

void MainInterface::setPidQlcdNumberColor()
{
    QString style="QLCDNumber {"
                  "   color: rgb(0, 255, 0);"          // 数字颜色
                  "   background-color: black;" // 背景颜色
                  "}";
    ui->lcdNumberPidAirT_MV->setStyleSheet(style);
    ui->lcdNumberPidAirT_MV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidAirT_PV->setStyleSheet(style);
    ui->lcdNumberPidAirT_PV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidAirT_SV->setStyleSheet(style);
    ui->lcdNumberPidAirT_SV->setSegmentStyle(QLCDNumber::Flat);

    ui->lcdNumberPidAirH_MV->setStyleSheet(style);
    ui->lcdNumberPidAirH_MV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidAirH_PV->setStyleSheet(style);
    ui->lcdNumberPidAirH_PV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidAirH_SV->setStyleSheet(style);
    ui->lcdNumberPidAirH_SV->setSegmentStyle(QLCDNumber::Flat);

    ui->lcdNumberPidLight_MV->setStyleSheet(style);
    ui->lcdNumberPidLight_MV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidLight_PV->setStyleSheet(style);
    ui->lcdNumberPidLight_PV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidLight_SV->setStyleSheet(style);
    ui->lcdNumberPidLight_SV->setSegmentStyle(QLCDNumber::Flat);

    ui->lcdNumberPidCO2_MV->setStyleSheet(style);
    ui->lcdNumberPidCO2_MV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidCO2_PV->setStyleSheet(style);
    ui->lcdNumberPidCO2_PV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidCO2_SV->setStyleSheet(style);
    ui->lcdNumberPidCO2_SV->setSegmentStyle(QLCDNumber::Flat);

    ui->lcdNumberPidSoilH_MV->setStyleSheet(style);
    ui->lcdNumberPidSoilH_MV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidSoilH_PV->setStyleSheet(style);
    ui->lcdNumberPidSoilH_PV->setSegmentStyle(QLCDNumber::Flat);
    ui->lcdNumberPidSoilH_SV->setStyleSheet(style);
    ui->lcdNumberPidSoilH_SV->setSegmentStyle(QLCDNumber::Flat);
}

void MainInterface::setMainSwitchStatus()
{
    QString style="QLCDNumber {"
                  "   color: rgb(255, 0, 0);"          // 数字颜色
            "   background-color: black;" // 背景颜色
            "}";

    ui->lcdNumberTest->setStyleSheet(style);
    ui->lcdNumberTest->setSegmentStyle(QLCDNumber::Flat);

    ui->lcdNumberCurrentDataCount->setStyleSheet(style);
    ui->lcdNumberCurrentDataCount->setSegmentStyle(QLCDNumber::Flat);

    ui->lcdNumberTime->setStyleSheet(style);
    ui->lcdNumberTime->setSegmentStyle(QLCDNumber::Flat);


}

void MainInterface::setPushButtonStyleSheet()
{
    ui->pushButtonMainSwitch->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonMainSwitch->setStyleSheet("border: none;");
    QIcon icon(":/res/res/switchPushbuttonOff.png");
    ui->pushButtonMainSwitch->setIcon(icon);
    ui->pushButtonMainSwitch->setIconSize(QSize(130, 40));

    ui->pushButtonSerialPortConfirm->setText("");
    ui->pushButtonSerialPortConfirm->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonSerialPortConfirm->setStyleSheet("border: none;");
    QIcon icon2(":/res/res/confirm.png");
    ui->pushButtonSerialPortConfirm->setIcon(icon2);
    ui->pushButtonSerialPortConfirm->setIconSize(QSize(85, 30));



    ui->pushButtonCtrlMode->setText("");
    ui->pushButtonCtrlMode->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonCtrlMode->setStyleSheet("border: none;");
    ui->pushButtonCtrlMode->setIcon(icon2);
    ui->pushButtonCtrlMode->setIconSize(QSize(85, 30));


    QIcon icon3(":/res/res/WhiteCO2.png");
    ui->pushButtonCO2Sensor->setText("");
    ui->pushButtonCO2Sensor->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonCO2Sensor->setStyleSheet("border: none;");
    ui->pushButtonCO2Sensor->setIcon(icon3);
    ui->pushButtonCO2Sensor->setIconSize(QSize(140, 35));

    QIcon icon4(":/res/res/WhiteLight.png");
    ui->pushButtonLightSensor->setText("");
    ui->pushButtonLightSensor->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonLightSensor->setStyleSheet("border: none;");
    ui->pushButtonLightSensor->setIcon(icon4);
    ui->pushButtonLightSensor->setIconSize(QSize(140, 35));

    QIcon icon5(":/res/res/WhiteAirT.png");
    ui->pushButtonAirTSensor->setText("");
    ui->pushButtonAirTSensor->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonAirTSensor->setStyleSheet("border: none;");
    ui->pushButtonAirTSensor->setIcon(icon5);
    ui->pushButtonAirTSensor->setIconSize(QSize(140, 35));

    QIcon icon6(":/res/res/WhiteAirH.png");
    ui->pushButtonAirHSensor->setText("");
    ui->pushButtonAirHSensor->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonAirHSensor->setStyleSheet("border: none;");
    ui->pushButtonAirHSensor->setIcon(icon6);
    ui->pushButtonAirHSensor->setIconSize(QSize(140, 35));

    QIcon icon7(":/res/res/WhiteSoilH.png");
    ui->pushButtonSoilHSensor->setText("");
    ui->pushButtonSoilHSensor->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonSoilHSensor->setStyleSheet("border: none;");
    ui->pushButtonSoilHSensor->setIcon(icon7);
    ui->pushButtonSoilHSensor->setIconSize(QSize(140, 35));

    QIcon icon8(":/res/res/WhiteWarningLED.png");
    ui->pushButtonWarningLED->setText("");
    ui->pushButtonWarningLED->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonWarningLED->setStyleSheet("border: none;");
    ui->pushButtonWarningLED->setIcon(icon8);
    ui->pushButtonWarningLED->setIconSize(QSize(140, 35));

    QIcon icon9(":/res/res/PidSoilHDisplay.png");//pid
    ui->pushButtonPidSoilHDisplay->setText("");
    ui->pushButtonPidSoilHDisplay->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonPidSoilHDisplay->setStyleSheet("border: none;" "padding: 0px;"  "border: none;"
           "background-color: transparent;" );
    ui->pushButtonPidSoilHDisplay->setIcon(icon9);
    ui->pushButtonPidSoilHDisplay->setIconSize(QSize(160, 35));




    QIcon icon10(":/res/res/PidAirHDisplay.png");//pid
    ui->pushButtonPidAirHDisplay->setText("");
    ui->pushButtonPidAirHDisplay->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonPidAirHDisplay->setStyleSheet("border: none;");
    ui->pushButtonPidAirHDisplay->setIcon(icon10);
    ui->pushButtonPidAirHDisplay->setIconSize(QSize(150, 35));

    QIcon icon11(":/res/res/PidCO2Display.png");//pid
    ui->pushButtonPidCO2Display->setText("");
    ui->pushButtonPidCO2Display->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonPidCO2Display->setStyleSheet("border: none;");
    ui->pushButtonPidCO2Display->setIcon(icon11);
    ui->pushButtonPidCO2Display->setIconSize(QSize(150, 35));

    QIcon icon12(":/res/res/PidLightDisplay.png");//pid
    ui->pushButtonPidLightDisplay->setText("");
    ui->pushButtonPidLightDisplay->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonPidLightDisplay->setStyleSheet("border: none;");
    ui->pushButtonPidLightDisplay->setIcon(icon12);
    ui->pushButtonPidLightDisplay->setIconSize(QSize(150, 35));

    QIcon icon13(":/res/res/PidAirTDisplay.png");//pid
    ui->pushButtonPidAirTDisplay->setText("");
    ui->pushButtonPidAirTDisplay->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonPidAirTDisplay->setStyleSheet("border: none;");
    ui->pushButtonPidAirTDisplay->setIcon(icon13);
    ui->pushButtonPidAirTDisplay->setIconSize(QSize(150, 35));

    QIcon icon14(":/res/res/WhiteGatherData.png");//pid
    ui->pushButton_12->setText("");
    ui->pushButton_12->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButton_12->setStyleSheet("border: none;");
    ui->pushButton_12->setIcon(icon14);
    ui->pushButton_12->setIconSize(QSize(140, 40));

    QIcon icon15(":/res/res/IrrigateDevice.png");//设备
    ui->pushButtonIrrigationEquipment->setText("");
    ui->pushButtonIrrigationEquipment->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonIrrigationEquipment->setStyleSheet("border: none;");
    ui->pushButtonIrrigationEquipment->setIcon(icon15);
    ui->pushButtonIrrigationEquipment->setIconSize(QSize(76, 27));

    QIcon icon16(":/res/res/VentilateDevice.png");//设备
    ui->pushButtonVentilatingEquipment->setText("");
    ui->pushButtonVentilatingEquipment->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonVentilatingEquipment->setStyleSheet("border: none;");
    ui->pushButtonVentilatingEquipment->setIcon(icon16);
    ui->pushButtonVentilatingEquipment->setIconSize(QSize(76, 27));

    QIcon icon17(":/res/res/CO2Adder.png");//设备
    ui->pushButtonCO2Interpolator->setText("");
    ui->pushButtonCO2Interpolator->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonCO2Interpolator->setStyleSheet("border: none;");
    ui->pushButtonCO2Interpolator->setIcon(icon17);
    ui->pushButtonCO2Interpolator->setIconSize(QSize(92, 27));

    QIcon icon18(":/res/res/RollerDoor.png");//设备
    ui->pushButtonRollUpDoor->setText("");
    ui->pushButtonRollUpDoor->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonRollUpDoor->setStyleSheet("border: none;");
    ui->pushButtonRollUpDoor->setIcon(icon18);
    ui->pushButtonRollUpDoor->setIconSize(QSize(75, 27));

    QIcon icon19(":/res/res/FillLight.png");//设备
    ui->pushButtonlightingEquipment->setText("");
    ui->pushButtonlightingEquipment->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonlightingEquipment->setStyleSheet("border: none;");
    ui->pushButtonlightingEquipment->setIcon(icon19);
    ui->pushButtonlightingEquipment->setIconSize(QSize(76, 27));

    QIcon icon20(":/res/res/WarmingUp.png");//设备
    ui-> pushButtonHeatingEquipment->setText("");
    ui-> pushButtonHeatingEquipment->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui-> pushButtonHeatingEquipment->setStyleSheet("border: none;");
    ui-> pushButtonHeatingEquipment->setIcon(icon20);
    ui-> pushButtonHeatingEquipment->setIconSize(QSize(76, 27));

    QIcon icon21(":/res/res/AirCoolerDevice.png");//设备
    ui->pushButtonAirCooler->setText("");
    ui->pushButtonAirCooler->setFlat(true);          // 设置按钮为"扁平"模式（移除背景和边框）
    ui->pushButtonAirCooler->setStyleSheet("border: none;");
    ui->pushButtonAirCooler->setIcon(icon21);
    ui->pushButtonAirCooler->setIconSize(QSize(75, 27));















}

void MainInterface::launchModSim32()
{

    //    QString program = R"(D:\modsim32\ModSim32.exe)"; // 替换为你的实际路径
    //        // 使用 startDetached 启动独立进程（不阻塞主程序）
    //        bool success = QProcess::startDetached(program);
    //        if (success) {
    //            qDebug() << "ModSim32 已启动";
    //        } else {
    //            qDebug() << "启动失败，请检查路径或权限";
    //        }

    QString exePath = R"(D:\modsim32\ModSim32.exe)";
    // 检查路径是否存在
    QFileInfo exeFile(exePath);
    if (!exeFile.exists())
    {
        qDebug() << "错误：ModSim32 可执行文件未找到！";
        return;
    }
    // 启动进程
    modsimProcess->start(exePath);

    // 监听进程状态变化
    connect(modsimProcess, &QProcess::stateChanged, [this](QProcess::ProcessState state) {
        if (state == QProcess::Running) {
            qDebug() << "ModSim32 已启动";




        } else if (state == QProcess::NotRunning) {
            qDebug() << "ModSim32 已关闭";


        }
    });

    // 错误处理
    connect(modsimProcess, &QProcess::errorOccurred, [](QProcess::ProcessError error) {
        qDebug() << "启动错误：" << error;
    });
}

void MainInterface::closeModSim32()
{
    if (modsimProcess->state() == QProcess::Running)
    {
        // 1. 尝试优雅终止（发送关闭请求）
        modsimProcess->terminate();
        // 等待最多 2 秒
        if (!modsimProcess->waitForFinished(2000))
        {
            // 2. 强制终止（如果优雅终止失败）
            modsimProcess->kill();
            qDebug() << "强制终止 ModSim32";
        }
    }
    else
    {
        qDebug() << "ModSim32 未运行";
    }
}

void MainInterface::initModSimProcess()
{
    modsimProcess=new QProcess(this);
}

void MainInterface::setModSim32PushButton(bool Status)
{
if(Status)
{
 ui->ModSim32PushButton_S->setText("ModSim32(ON)");
 ui->ModSim32PushButton_S->setStyleSheet("QPushButton {"
 "   background-color: rgb(0,255,0);"
 "   color: rgb(0,0,0);"
 "   border-radius: 20px;"
 "   border: 3px solid rgb(255, 255, 255);"
 "   padding: 5px 15px;"
 "}"
 "QPushButton:hover {"
 "   background-color: rgb(0, 255, 255);"
 "}"
 "QPushButton:pressed {"
 "   background-color: rgb(0, 170, 255);"
 "}");

}
else
{
ui->ModSim32PushButton_S->setText("ModSim32(OFF)");
ui->ModSim32PushButton_S->setStyleSheet("QPushButton {"
"   background-color: rgb(255,255,255);"
"   color: rgb(0,0,0);"
"   border-radius: 20px;"
"   border: 3px solid rgb(255, 255, 255);"
"   padding: 5px 15px;"
"}"
"QPushButton:hover {"
"   background-color: rgb(0, 255, 255);"
"}"
"QPushButton:pressed {"
"   background-color: rgb(0, 170, 255);"
"}");

}
}


bool MainInterface::linkingDevice(bool index)//接受某种条件后进行连接；todo.....................2025/4/22/16:49
{


    DeviceSerialportControl::instance();


}




void MainInterface::on_pushButtonMainSwitch_clicked()
{   extern deviceStatusDataBlock DeviceStatusDataBlock;
    extern bool MainSwitch;

    bool status=MainSwitch;//0 1两种状态 0表示关，1表示开


    if(status)//
    {

        ui->pushButtonMainSwitch->setChecked(false);
        bool status= ui->pushButtonMainSwitch->isChecked();
        MainSwitch=status;
        QIcon icon(":/res/res/switchPushbuttonOff.png");
        ui->pushButtonMainSwitch->setIcon(icon);
        ui->pushButtonMainSwitch->setIconSize(QSize(130, 40));
//        ui->pushButtonMainSwitch->setText("关----");
        DeviceStatusDataBlock.mainSwitch_LED=status;//关闭系统
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,0,false);
        //设置对应modsim主开关的值为false todo......
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(0, false,false);

        setDeviceStatusDataBlock(false);
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock);
        turnOffDeviceDisplay();
        ui->lcdNumberTest->display(MainSwitch);

        connectSerialPort(MainSwitch);




    }
    else{

        ui->pushButtonMainSwitch->setChecked(true);
        QIcon icon(":/res/res/switchPushbuttonOn.png");
        ui->pushButtonMainSwitch->setIcon(icon);
        ui->pushButtonMainSwitch->setIconSize(QSize(130, 40));
//          ui->pushButtonMainSwitch->setText("开-----");
        bool status=ui->pushButtonMainSwitch->isChecked();
        MainSwitch=status;
        DeviceStatusDataBlock.mainSwitch_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,0,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(0, true,false);
        ui->lcdNumberTest->display(MainSwitch);
       // MonitorDevice::instance();//开启检测设备

        connectSerialPort(MainSwitch);

        AlarmAlertTone::instance();
        ManualControl::instance();//人工控制初始化
        PidController ::instance();//自动控制初始化
        setPidSetPointValue();//初始化PIdSV值
        WarningInformation::instance();//初始化警报信息


    }


}


void MainInterface::on_radioButtonG1_1_clicked()//灌溉设备
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG1_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.IrrigationEquipment_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,1,false);
         //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(1,true,true);
        ui->labelG1->setText("开启状态");
        refreshDeviceStatusLEDONorOff(1,true);
        //打开对应的modsim的值
        //发送打开灌溉设备的信号
        if(!ui->comboBoxIrrigationSelection->currentIndex())
        {
            emit sendPushbuttonG1_1(true);
        }
        else
        {

            emit sendPushbuttonG1_2(true);//发送灌溉土壤
        }


    }
}


void MainInterface::on_radioButtonG1_2_clicked()
{   extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG1_2->isChecked();
    if(status)
    {   DeviceStatusDataBlock.IrrigationEquipment_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,1,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(1, false,true);
        ui->labelG1->setText("关闭状态");
        refreshDeviceStatusLEDONorOff(1,false);

        //关闭对应的modsim的值
        //发送关闭灌溉设备的信号
        if(!ui->comboBoxIrrigationSelection->currentIndex())
        {
            emit sendPushbuttonG1_1(false);
        }
        else
        {
            emit sendPushbuttonG1_2(false);//关闭灌溉土壤
        }

    }
}


void MainInterface::on_pushButtonCtrlMode_clicked()
{
    extern bool MainSwitch;
    if(MainSwitch){
        int index=ui->CtrlMode->currentIndex();
        if(index==0)//手动模式
        {
            ctrlMode=false;
            setRadioCheckabel(!ctrlMode);
//            QString text=ui->CtrlMode->currentText();
//            ui->lModeTest->setText(text);
            extern bool AutoControlStatus;
            extern bool AutoControlStatus2;
            extern bool AutoControlStatus3;
            AutoControlStatus=false;
            AutoControlStatus2=AutoControlStatus;
            AutoControlStatus3=AutoControlStatus;
            //emit sendAutoControl(ctrlMode);//关闭自动控制

        }
        else//自动模式
        {
            ctrlMode=true;
            setRadioCheckabel(!ctrlMode);
//            QString text=ui->CtrlMode->currentText();
//            ui->lModeTest->setText(text);
            extern bool AutoControlStatus;
            extern bool AutoControlStatus2;
            extern bool AutoControlStatus3;
            AutoControlStatus=true;
            AutoControlStatus2=AutoControlStatus;
            AutoControlStatus3=AutoControlStatus;
            //emit sendAutoControl(ctrlMode);//打开自动控制

        }

    }
}

void MainInterface::on_radioButtonG2_1_clicked()//风机风扇
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG2_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,2,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(2, true,true);
        ui->labelG2->setText("开启状态");
        refreshDeviceStatusLEDONorOff(2,true);
        if(ui->comboBoxVentilationSelection->currentIndex()==0)
        {
        emit sendPushbuttonG2_1(true);//降低空气湿度打开
        }
        else if(ui->comboBoxVentilationSelection->currentIndex()==1)
        {


         emit sendPushbuttonG2_2(true);//降低CO2浓度打开

        }
        else
        {
         emit sendPushbuttonG2_3(true);//降低土壤湿度打开

        }

    }
}


void MainInterface::on_radioButtonG2_2_clicked()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG2_2->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,2,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(2, false,true);
        ui->labelG2->setText("关闭状态");
        refreshDeviceStatusLEDONorOff(2,false);
        if(ui->comboBoxVentilationSelection->currentIndex()==0)
        {
           emit sendPushbuttonG2_1(false);//降低空气湿度关闭
        }
        else if(ui->comboBoxVentilationSelection->currentIndex()==1)
        {


           emit sendPushbuttonG2_2(false);//降低CO2浓度关闭

        }
        else
        {
          emit sendPushbuttonG2_3(false);//降低土壤湿度关闭

        }

    }
}


void MainInterface::on_radioButtonG3_1_clicked()//CO2
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG3_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.CO2Interpolator_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,3,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(3, true,true);
        ui->labelG3->setText("开启状态");
         refreshDeviceStatusLEDONorOff(3,true);
        emit sendPushbuttonG3(true);//打开CO2增加器

    }
}


void MainInterface::on_radioButtonG3_2_clicked()//
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG3_2->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.CO2Interpolator_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,3,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(3, false,true);
        ui->labelG3->setText("关闭状态");
         refreshDeviceStatusLEDONorOff(3,false);
        emit sendPushbuttonG3(false);//打开CO2增加器

    }
}


void MainInterface::on_radioButtonG4_1_clicked()//卷帘机
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG4_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.rollUpDoor_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,4,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(4, true,true);
        ui->labelG4->setText("开启状态");
           refreshDeviceStatusLEDONorOff(4,true);
        emit sendPushbuttonG4(true);//降低光照强度设备打开

    }
}
void MainInterface::on_radioButtonG4_2_clicked()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG4_2->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.rollUpDoor_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,4,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(4, false,true);
        ui->labelG4->setText("关闭状态");
         refreshDeviceStatusLEDONorOff(4,false);
        emit sendPushbuttonG4(false);//降低光照强度设备关闭

    }
}


void MainInterface::on_radioButtonG5_1_clicked()//light灯光
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG5_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.lightingEquipment_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,5,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(5, true,true);
        ui->labelG5->setText("开启状态");
         refreshDeviceStatusLEDONorOff(5,true);
        emit sendPushbuttonG5(true);//打开增加光照强度的设备

    }
}


void MainInterface::on_radioButtonG5_2_clicked()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG5_2->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.lightingEquipment_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,5,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(5, false,true);
        ui->labelG5->setText("关闭状态");
         refreshDeviceStatusLEDONorOff(5,false);
        emit sendPushbuttonG5(false);//关闭增加光照强度的设备

    }
}

void MainInterface::on_radioButtonG6_1_clicked()//加热器打开
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG6_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.heatingEquipment_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,6,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(6, true,true);
        ui->labelG6->setText("开启状态");
         refreshDeviceStatusLEDONorOff(6,true);
        emit sendPushbuttonG6(true);//发送打开加热器的信号

    }
}
void MainInterface::on_radioButtonG6_2_clicked()//加热器关闭
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG6_2->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.heatingEquipment_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,6,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(6, false,true);
        ui->labelG6->setText("关闭状态");
        refreshDeviceStatusLEDONorOff(6,false);
         emit sendPushbuttonG6(false);//发送关闭加热器的信号
    }
}


void MainInterface::on_radioButtonG7_1_clicked()//冷风机
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG7_1->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.airCooler_LED=status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,7,false);
        //设置对应modsim主开关的值为true
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(7, true,true);
        ui->labelG7->setText("开启状态");
        refreshDeviceStatusLEDONorOff(7,true);
        emit sendPushbuttonG7(true);//发送打开冷风机的信号

    }
}

void MainInterface::on_radioButtonG7_2_clicked()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    bool status=ui->radioButtonG7_2->isChecked();
    if(status)
    {
        DeviceStatusDataBlock.airCooler_LED=!status;
        setDeviceStatusLEDONorOff(DeviceStatusDataBlock,7,false);
        //设置对应modsim主开关的值为false
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(7, false,true);
        ui->labelG7->setText("关闭状态");
        refreshDeviceStatusLEDONorOff(7,false);
        emit sendPushbuttonG7(false);//发送打开冷风机的信号

    }
}




void MainInterface::on_logOutPushButton_S_clicked()
{
 extern UserInfo currentUserInfo;//存储当前用户信息
//将报警信息存储大数据库当中todo...........
//将本次的程序运行的报警次数更新到QVector中
    UserMysqlS::instance()->updateSensorWarningTimes();
//将推出系统入日志
QString currentUserType;
MainWindow::QStringUserType(currentUserInfo.userType, currentUserType);
if(currentUserInfo.userName=="")
{
    LogRecord::instance()->writeLogRecord("退出系统","无","用户");
}
else
{

    LogRecord::instance()->writeLogRecord("退出系统",currentUserInfo.userName,currentUserType);
}
LogRecord::instance()->writeLogRecord("退出系统",currentUserInfo.userName,currentUserType);
    int ret = QMessageBox::question(
                this,         // 父窗口
                "退出系统",     // 标题
                "确定要退出系统吗？",// 内容
                QMessageBox::Yes | QMessageBox::No // 按钮选项
                );

    if (ret == QMessageBox::Yes) {

        // 用户选择“是”
        //        MainWindow::instance()->~MainWindow();
        //        userMysql::instance()->~userMysql();
        //        ModBusManger::instance()->~ModBusManger();
        //          MainWindow::instance()->close();

//        QApplication::exit();
         this->close();
        qDebug()<<"close---------->Maininterface()";

        qDebug()<<"close---------->MainWindow()";
        MainWindow::instance()->quitSystem();
        closeModSim32();//如果未手动关闭则系统会关闭ModSim32


    } else {
        // 用户选择“否”

    }

}


void MainInterface::on_userListPushButton_S_clicked()
{


UserManageMent::instance()->show();






}


void MainInterface::on_pushButtonHistoryData_clicked()
{
// 用来显示数据库数据todo.........
SensorDataDisplayInterface::instance()->show();
SensorDataDisplayInterface::instance()->displaySensorData();











}


void MainInterface::on_pushButtonSerialPortConfirm_clicked()
{

//设置串口
//int
    extern int serialPortOpenMode;//0为自动；1为手动
    if(!ui->serialPortOpenMode->currentIndex())//自动模式
    {
       serialPortOpenMode=0;
       emit sendMainSwitchEnabel();
       return;
    }else
    {
        serialPortOpenMode=1;//手动模式
    }
    SerialPortSet::instance()->show();


}


void MainInterface::on_dynamicCurvePushButton_S_clicked()
{
//动态曲线
       DynamicCurveDisplayInterface::instance()->show();
       extern bool MainSwitch;//系统总开关默然是关
       extern bool DynamicCurveStatus;
       if(MainSwitch)
       {
       DynamicCurveStatus=true;
       qDebug()<<"dynamic";

       }


//    UserMysqlS::instance()->test();

}

void MainInterface::refreshDeviceStatusLEDONorOff(int index,bool status)
{
 extern deviceStatusDataBlock DeviceStatusDataBlock;
 setDeviceStatusLEDONorOff(DeviceStatusDataBlock,index);
 switch(index)//刷新设备----->按钮显示
 {

 case 0:
if(status)
{
    ui->pushButtonMainSwitch->setChecked(true);

    //ui->pushButtonMainSwitch->setText("开");
    QIcon icon(":/res/res/switchPushbuttonOn.png");
    ui->pushButtonMainSwitch->setIcon(icon);
    ui->pushButtonMainSwitch->setIconSize(QSize(130, 40));
    bool status=ui->pushButtonMainSwitch->isChecked();
    ui->lcdNumberTest->display(status);
    connectSerialPort(status);
}
else{

    ui->pushButtonMainSwitch->setChecked(false);
    bool status= ui->pushButtonMainSwitch->isChecked();
    QIcon icon(":/res/res/switchPushbuttonOff.png");
    ui->pushButtonMainSwitch->setIcon(icon);
    ui->pushButtonMainSwitch->setIconSize(QSize(130, 40));
   // ui->pushButtonMainSwitch->setText("关");
    turnOffDeviceDisplay();
    ui->lcdNumberTest->display(status);
    connectSerialPort(status);

}
 case 1:
     if(status)
     {
           ui->labelG1->setText("开启状态");
           ui->labelG1->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");

           ui->radioButtonG1_1->setCheckable(true);
           ui->radioButtonG1_1->setChecked(true);
     }else
     {
      ui->labelG1->setText("关闭状态");//todo............................继续努力！
      ui->labelG1->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG1_2->setCheckable(true);
      ui->radioButtonG1_2->setChecked(true);

     }


     break;
 case 2:
     if(status)
     {
           ui->labelG2->setText("开启状态");
           ui->labelG2->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");
           ui->radioButtonG2_1->setCheckable(true);
           ui->radioButtonG2_1->setChecked(true);
     }else
     {
      ui->labelG2->setText("关闭状态");//todo............................继续努力！
      ui->labelG2->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG2_2->setCheckable(true);
      ui->radioButtonG2_2->setChecked(true);

     }
     break;
 case 3:
     if(status)
     {
           ui->labelG3->setText("开启状态");
           ui->labelG3->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");
           ui->radioButtonG3_1->setCheckable(true);
           ui->radioButtonG3_1->setChecked(true);
     }else
     {
      ui->labelG3->setText("关闭状态");//todo............................继续努力！
      ui->labelG3->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG3_2->setCheckable(true);
      ui->radioButtonG3_2->setChecked(true);

     }
     break;
 case 4:
     if(status)
     {
           ui->labelG4->setText("开启状态");
           ui->labelG4->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");
           ui->radioButtonG4_1->setCheckable(true);
           ui->radioButtonG4_1->setChecked(true);
     }else
     {
      ui->labelG4->setText("关闭状态");//todo............................继续努力！
      ui->labelG4->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG4_2->setCheckable(true);
      ui->radioButtonG4_2->setChecked(true);

     }
     break;
 case 5:
     if(status)
     {
           ui->labelG5->setText("开启状态");
           ui->labelG5->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");
           ui->radioButtonG5_1->setCheckable(true);
           ui->radioButtonG5_1->setChecked(true);
     }else
     {
      ui->labelG5->setText("关闭状态");//todo............................继续努力！
      ui->labelG5->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG5_2->setCheckable(true);
      ui->radioButtonG5_2->setChecked(true);

     }
     break;
 case 6:
     if(status)
     {
           ui->labelG6->setText("开启状态");
           ui->labelG6->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");
           ui->radioButtonG6_1->setCheckable(true);
           ui->radioButtonG6_1->setChecked(true);
     }else
     {
      ui->labelG6->setText("关闭状态");//todo............................继续努力！
      ui->labelG6->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG6_2->setCheckable(true);
      ui->radioButtonG6_2->setChecked(true);

     }
     break;
 case 7:
     if(status)
     {
           ui->labelG7->setText("开启状态");
           ui->labelG7->setStyleSheet("color: rgb(0,255,0);" "background-color: rgb(0,0,0);");
           ui->radioButtonG7_1->setCheckable(true);
           ui->radioButtonG7_1->setChecked(true);
     }else
     {
      ui->labelG7->setText("关闭状态");//todo............................继续努力！
      ui->labelG7->setStyleSheet("color:rgb(170, 0, 0);" "background-color: rgb(0,0,0);");
      ui->radioButtonG7_2->setCheckable(true);
      ui->radioButtonG7_2->setChecked(true);

     }
     break;


 }


}


void MainInterface::on_pushButtonModsimDeviceSwitch_clicked()
{
extern bool modSimDeviceSwitch;
if(modSimDeviceSwitch)
{
modSimDeviceSwitch=false;
qDebug()<<"modsimOff";
DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(9, false,true);
emit sendMosimDeviceSwitchStatus(modSimDeviceSwitch);
ui->pushButtonModsimDeviceSwitch->setCheckable(false);
ui->pushButtonModsimDeviceSwitch->setText("modsimDeviceOff");

}
else
{

    modSimDeviceSwitch=true;
    qDebug()<<"modsimOn";
    DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(9, true,true);
    emit sendMosimDeviceSwitchStatus(modSimDeviceSwitch);
    ui->pushButtonModsimDeviceSwitch->setCheckable(true);
    ui->pushButtonModsimDeviceSwitch->setText("modsimDeviceOn");

}















}


void MainInterface::on_switchUserPushButton_S_clicked()
{
MainWindow::instance()->show();
this->close();

}





void MainInterface::on_warningPushButton_S_clicked()
{
//WarningInformation::instance()->writeWarningInformation();

WarningInformation::instance()->writePlainTextEdit();
WarningInformation::instance()->show();


}


void MainInterface::on_parameterSetingPushButton_S_clicked()
{

 SensorThresholdParametersSet::instance()->displaySensorThresholdParametersSetTable();
 SensorThresholdParametersSet::instance()->show();



}


void MainInterface::on_timePushButton_S_clicked()//时间设置
{

TimeParameterSet::instance()->show();//显示时间设置界面





}


void MainInterface::on_logPushbutton_S_clicked()
{
//    //SenData.Time=QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
//    QString currentTime=QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
     LogRecord::instance()->writeLogRecord("hellword");
     LogRecord::instance()->writePlainTextEdit();
     //LogRecord::instance()->openLogFileExternal();
     LogRecord::instance()->show();

}

void MainInterface::warningLed(bool ok)
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;
    DeviceStatusDataBlock.warningLed=ok;
    setDeviceStatusLEDONorOff(DeviceStatusDataBlock,8,false);
    if(!ok)
    {
         emit sendAlarmTipSound();
    }
}

void MainInterface::warningAirTLED(int status)
{
    if(status==1)
    {

       ui->labelAirTemperatureStatus->setText("空气温度过高");
       smallLED.warning_AirT=false;

       setWarningSmallLEDStatus(smallLED,0,false);

    }
    else if(status==-1)
    {

      ui->labelAirTemperatureStatus->setText("空气温度过低");
      smallLED.warning_AirT=false;
      setWarningSmallLEDStatus(smallLED,0,false);

    }
    else if(status==0)
    {
        ui->labelAirTemperatureStatus->setText("空气温度正常");
        smallLED.warning_AirT=true;
        setWarningSmallLEDStatus(smallLED,0,false);

    }
}

void MainInterface::warningAirHLED(int status)
{
    if(status==1)
        {

           ui->labelAirHumidityStatus->setText("空气湿度过高");
           smallLED.warning_AirH=false;

           setWarningSmallLEDStatus(smallLED,1,false);
        }
        else if(status==-1)
        {

          ui->labelAirHumidityStatus->setText("空气湿度过低");
          smallLED.warning_AirH=false;
          setWarningSmallLEDStatus(smallLED,1,false);
        }
        else if(status==0)
        {
            ui->labelAirHumidityStatus->setText("空气湿度正常");
            smallLED.warning_AirH=true;
            setWarningSmallLEDStatus(smallLED,1,false);
        }
}

void MainInterface::warningLightLED(int status)
{
    if(status==1)
        {

           ui->labelLightStatus->setText("光照强度过高");
           smallLED.warning_Light=false;

           setWarningSmallLEDStatus(smallLED,2,false);
        }
        else if(status==-1)
        {

          ui->labelLightStatus->setText("光照强度过低");
          smallLED.warning_Light=false;
          setWarningSmallLEDStatus(smallLED,2,false);
        }
        else if(status==0)
        {
            ui->labelLightStatus->setText("光照强度正常");
            smallLED.warning_Light=true;
            setWarningSmallLEDStatus(smallLED,2,false);
        }
}

void MainInterface::warningCO2LED(int status)
{
    if(status==1)
        {

           ui->labelCO2Status->setText("CO2浓度过高");
           smallLED.warning_CO2=false;

           setWarningSmallLEDStatus(smallLED,3,false);
        }
        else if(status==-1)
        {

          ui->labelCO2Status->setText("CO2浓度过低");
          smallLED.warning_CO2=false;
          setWarningSmallLEDStatus(smallLED,3,false);
        }
        else if(status==0)
        {
            ui->labelCO2Status->setText("CO2浓度正常");
            smallLED.warning_CO2=true;
            setWarningSmallLEDStatus(smallLED,3,false);
        }
}

void MainInterface::warningSoilHLED(int status)
{
    if(status==1)
        {

           ui->labelSoilHumidityStatus->setText("土壤湿度过高");
           smallLED.warning_SoilH=false;

           setWarningSmallLEDStatus(smallLED,4,false);
        }
        else if(status==-1)
        {

          ui->labelSoilHumidityStatus->setText("土壤湿度过低");
          smallLED.warning_SoilH=false;
          setWarningSmallLEDStatus(smallLED,4,false);
        }
        else if(status==0)
        {
            ui->labelSoilHumidityStatus->setText("土壤湿度正常");
            smallLED.warning_SoilH=true;
            setWarningSmallLEDStatus(smallLED,4,false);
    }
}



void MainInterface::autoControlAirTemperatureDeviceLED(int index)
{
//setDeviceStatusLEDONorOff()
     extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(index==6)//打开加热器
    {
     DeviceStatusDataBlock.heatingEquipment_LED=true;
     setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);
     refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.heatingEquipment_LED);//设置设备状态；
     DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
     deviceIndex[0]=6;
    }
    else if(index==7)
    {
        DeviceStatusDataBlock.airCooler_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);//打开冷风机
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.airCooler_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
         deviceIndex[0]=7;
    }
    //启动定时器3s
    ui->lcdNumberPidAirT_MV->display(25);
    setQlcdNumberColor(0,false,false);
    AutoTimer[0]->start(3000);

}

void MainInterface::closeAirTemperatureDeviceLED()
{

extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
if(deviceIndex[0]==6)//关闭加热器
{
    DeviceStatusDataBlock.heatingEquipment_LED=false;
    setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[0]);//
    refreshDeviceStatusLEDONorOff(deviceIndex[0], DeviceStatusDataBlock.heatingEquipment_LED);//设置设备状态；
    DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[0], false,true);
    deviceIndex[0]=0;
}
else if(deviceIndex[0]==7)//关闭冷风机
{
    DeviceStatusDataBlock.airCooler_LED=false;
    setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[0]);//
    refreshDeviceStatusLEDONorOff(deviceIndex[0], DeviceStatusDataBlock.airCooler_LED);//设置设备状态；
    DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[0], false,true);
    deviceIndex[0]=0;
}
 ui->lcdNumberPidAirT_MV->display(0);
 setQlcdNumberColor(0,true,false);

}

void MainInterface::closeAirTemperatureDeviceLEDNormal()
{
extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
if(DeviceStatusDataBlock.heatingEquipment_LED)
{

    DeviceStatusDataBlock.heatingEquipment_LED=false;
    setDeviceStatusLEDONorOff( DeviceStatusDataBlock,6);//
    refreshDeviceStatusLEDONorOff(6, DeviceStatusDataBlock.heatingEquipment_LED);//设置设备状态；
    DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(6, false,true);
    ui->lcdNumberPidAirT_MV->display(0);
    setQlcdNumberColor(6,true,false);


}
if(DeviceStatusDataBlock.airCooler_LED)
{
 DeviceStatusDataBlock.airCooler_LED=false;
 setDeviceStatusLEDONorOff( DeviceStatusDataBlock,7);//
 refreshDeviceStatusLEDONorOff(7, DeviceStatusDataBlock.airCooler_LED);//设置设备状态；
 DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(7, false,true);
 ui->lcdNumberPidAirT_MV->display(0);
 setQlcdNumberColor(0,true,false);

}

}

void MainInterface::autoControlLightIntensityDeviceLED(int index)
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(index==4)//打开卷帘门
    {
        DeviceStatusDataBlock.rollUpDoor_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);//
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.rollUpDoor_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[2]=4;
    }
    else if(index==5)//补光灯
    {
        DeviceStatusDataBlock.lightingEquipment_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.lightingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[2]=5;
    }
   //启动定时器3s
   ui->lcdNumberPidLight_MV->display(35);
    setQlcdNumberColor(2,false,false);
   AutoTimer[2]->start(3000);

}

void MainInterface::closeLightIntensityDeviceLED()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(deviceIndex[2]==4)
    {
        DeviceStatusDataBlock.rollUpDoor_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[2]);//关闭卷帘
        refreshDeviceStatusLEDONorOff(deviceIndex[2], DeviceStatusDataBlock.rollUpDoor_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[2], false,true);
        deviceIndex[2]=0;
    }
    else if(deviceIndex[2]==5)
    {
        DeviceStatusDataBlock.lightingEquipment_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[2]);//关闭灯光
        refreshDeviceStatusLEDONorOff(deviceIndex[2], DeviceStatusDataBlock.lightingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[2], false,true);
        deviceIndex[2]=0;
    }
      ui->lcdNumberPidLight_MV->display(0);
      setQlcdNumberColor(2,true,false);
}

void MainInterface::closeLightIntensityDeviceLEDNormal()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(DeviceStatusDataBlock.rollUpDoor_LED)//卷帘门
    {

        DeviceStatusDataBlock.rollUpDoor_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,4);//
        refreshDeviceStatusLEDONorOff(4, DeviceStatusDataBlock.rollUpDoor_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(4, false,true);
        ui->lcdNumberPidLight_MV->display(0);
        setQlcdNumberColor(2,true,false);


    }
    if(DeviceStatusDataBlock.lightingEquipment_LED)
    {
     DeviceStatusDataBlock.lightingEquipment_LED=false;
     setDeviceStatusLEDONorOff( DeviceStatusDataBlock,5);//
     refreshDeviceStatusLEDONorOff(5, DeviceStatusDataBlock.lightingEquipment_LED);//设置设备状态；
     DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(5, false,true);
     ui->lcdNumberPidLight_MV->display(0);
     setQlcdNumberColor(2,true,false);

    }
}

void MainInterface::autoControlAirHumidityDeviceLED(int index, int selectIndex)
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(index==1)//打开灌溉-------设备空气湿度低
    {
        DeviceStatusDataBlock.IrrigationEquipment_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);//
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.IrrigationEquipment_LED);//设置设备状态；
        ui->comboBoxIrrigationSelection->setCurrentIndex(selectIndex);
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[1]=1;
    }
    else if(index==2)//通风设备---------空气湿度大
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        ui->comboBoxVentilationSelection->setCurrentIndex(selectIndex);
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);

        deviceIndex[1]=2;
    }
   //启动定时器3s
    ui->lcdNumberPidAirH_MV->display(67);
    setQlcdNumberColor(1,false,false);
   AutoTimer[1]->start(3000);
}

void MainInterface::closeAirHumidityDeviceLED()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(deviceIndex[1]==1)
    {
        DeviceStatusDataBlock.IrrigationEquipment_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[1]);//关闭灌溉
        refreshDeviceStatusLEDONorOff(deviceIndex[1], DeviceStatusDataBlock.IrrigationEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[1], false,true);
        ui->comboBoxIrrigationSelection->setCurrentIndex(2);
        deviceIndex[1]=0;
    }
    else if(deviceIndex[1]==2)
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[1]);//关闭通风
        refreshDeviceStatusLEDONorOff(deviceIndex[1], DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[1], false,true);
        ui->comboBoxVentilationSelection->setCurrentIndex(3);
        deviceIndex[1]=0;
    }
     ui->lcdNumberPidAirH_MV->display(0);
     setQlcdNumberColor(1,true,false);
}

void MainInterface::closeAirHumidityDeviceLEDNormal()//---->两个设备----》灌溉 、通风
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块......todo
    if(ui->comboBoxIrrigationSelection->currentIndex()==0)
    {
        if(DeviceStatusDataBlock.IrrigationEquipment_LED)
        {

            DeviceStatusDataBlock.IrrigationEquipment_LED=false;
            setDeviceStatusLEDONorOff( DeviceStatusDataBlock,1);//关闭灌溉
            refreshDeviceStatusLEDONorOff(1, DeviceStatusDataBlock.IrrigationEquipment_LED);//设置设备状态；
            DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(1, false,true);
            ui->comboBoxIrrigationSelection->setCurrentIndex(2);

        }

    }
    if(ui->comboBoxVentilationSelection->currentIndex()==0)
    {

       if(DeviceStatusDataBlock.ventilatingEquipment_LED)
       {

           DeviceStatusDataBlock.ventilatingEquipment_LED=false;
           setDeviceStatusLEDONorOff( DeviceStatusDataBlock,2);//关闭通风
           refreshDeviceStatusLEDONorOff(2, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
           DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(2, false,true);
           ui->comboBoxVentilationSelection->setCurrentIndex(3);

       }



    }
     ui->lcdNumberPidAirH_MV->display(0);
     setQlcdNumberColor(1,true,false);
}

void MainInterface::autoControlCO2ConcentrationDeviceLED(int index, int selectIndex)
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(index==2)//打开通风设备-------降低CO2浓度
     {
        DeviceStatusDataBlock.ventilatingEquipment_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);//
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        ui->comboBoxVentilationSelection->setCurrentIndex(selectIndex);
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[3]=2;
    }
    else if(index==3)//CO2添加器
    {
        DeviceStatusDataBlock.CO2Interpolator_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.CO2Interpolator_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[3]=3;
    }
   //启动定时器3s
   ui->lcdNumberPidCO2_MV->display(1150);
   setQlcdNumberColor(3,false,false);
   AutoTimer[3]->start(3000);
}

void MainInterface::closeCO2ConcentrationDeviceLED()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(deviceIndex[3]==2)
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[3]);//关闭通风
        refreshDeviceStatusLEDONorOff(deviceIndex[3], DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[3], false,true);
        ui->comboBoxVentilationSelection->setCurrentIndex(3);
        deviceIndex[3]=0;
    }
    else if(deviceIndex[3]==3)
    {
        DeviceStatusDataBlock.CO2Interpolator_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[3]);//关闭CO添加器
        refreshDeviceStatusLEDONorOff(deviceIndex[3], DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[3], false,true);
        deviceIndex[3]=0;
    }
      ui->lcdNumberPidCO2_MV->display(0);
      setQlcdNumberColor(3,true,false);
}

void MainInterface::closeCO2ConcentrationDeviceLEDNormal()
{



    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(ui->comboBoxVentilationSelection->currentIndex()==1)
    {

        if(DeviceStatusDataBlock.ventilatingEquipment_LED)
        {
            DeviceStatusDataBlock.ventilatingEquipment_LED=false;
            setDeviceStatusLEDONorOff( DeviceStatusDataBlock,2);//关闭通风
            refreshDeviceStatusLEDONorOff(2, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
            DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(2, false,true);
            ui->comboBoxVentilationSelection->setCurrentIndex(3);

        }

    }

    if(DeviceStatusDataBlock.CO2Interpolator_LED)
    {

        DeviceStatusDataBlock.CO2Interpolator_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,3);//关闭CO添加器
        refreshDeviceStatusLEDONorOff(3, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(3, false,true);




    }

      ui->lcdNumberPidCO2_MV->display(0);
      setQlcdNumberColor(3,true,false);
















}

void MainInterface::autoControlSoilMoistureDeviceLED(int index, int selectIndex)
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(index==1)//打开灌溉-------增加设备土壤湿度
    {
        DeviceStatusDataBlock.IrrigationEquipment_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);//
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.IrrigationEquipment_LED);//设置设备状态；
        ui->comboBoxIrrigationSelection->setCurrentIndex(selectIndex);
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[4]=1;
    }
    else if(index==2)//通风设备---------降低土壤湿度
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=true;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,index);
        refreshDeviceStatusLEDONorOff(index, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        ui->comboBoxVentilationSelection->setCurrentIndex(selectIndex);
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(index, true,true);
        deviceIndex[4]=2;
    }
   //启动定时器3s
   ui->lcdNumberPidSoilH_MV->display(72);
   setQlcdNumberColor(4,false,false);
   AutoTimer[4]->start(3000);
}

void MainInterface::closeSoilMoistureDeviceLED()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(deviceIndex[4]==1)
    {
        DeviceStatusDataBlock.IrrigationEquipment_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[4]);//关闭灌溉
        refreshDeviceStatusLEDONorOff(deviceIndex[4], DeviceStatusDataBlock.IrrigationEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[4], false,true);
        ui->comboBoxIrrigationSelection->setCurrentIndex(2);
        deviceIndex[4]=0;
    }
    else if(deviceIndex[4]==2)
    {
        DeviceStatusDataBlock.ventilatingEquipment_LED=false;
        setDeviceStatusLEDONorOff( DeviceStatusDataBlock,deviceIndex[4]);//关闭通风
        refreshDeviceStatusLEDONorOff(deviceIndex[4], DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
        DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(deviceIndex[4], false,true);
        ui->comboBoxVentilationSelection->setCurrentIndex(3);
        deviceIndex[4]=0;
    }
    ui->lcdNumberPidSoilH_MV->display(0);
    setQlcdNumberColor(4,true,false);
}

void MainInterface::closeSoilMoistureDeviceLEDNormal()
{
    extern deviceStatusDataBlock DeviceStatusDataBlock;//设备状态块
    if(ui->comboBoxIrrigationSelection->currentIndex()==1)
    {

        if(DeviceStatusDataBlock.IrrigationEquipment_LED)
        {

            DeviceStatusDataBlock.IrrigationEquipment_LED=false;
            setDeviceStatusLEDONorOff( DeviceStatusDataBlock,1);//关闭灌溉
            refreshDeviceStatusLEDONorOff(1, DeviceStatusDataBlock.IrrigationEquipment_LED);//设置设备状态；
            DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(1, false,true);
            ui->comboBoxIrrigationSelection->setCurrentIndex(2);

        }

    }
    if(ui->comboBoxVentilationSelection->currentIndex()==2)
    {

        if(DeviceStatusDataBlock.ventilatingEquipment_LED)
        {


            DeviceStatusDataBlock.ventilatingEquipment_LED=false;
            setDeviceStatusLEDONorOff( DeviceStatusDataBlock,2);//关闭通风
            refreshDeviceStatusLEDONorOff(2, DeviceStatusDataBlock.ventilatingEquipment_LED);//设置设备状态；
            DeviceSerialportControl::instance()->setDeviceStatusLEDONorOff(2, false,true);
            ui->comboBoxVentilationSelection->setCurrentIndex(3);


        }


    }

    ui->lcdNumberPidSoilH_MV->display(0);
    setQlcdNumberColor(4,true,false);
}




void MainInterface::on_pidParameterSetPushbutton_S_clicked()
{
PidParameterSet::instance()->displayPidParameterSetTable();
PidParameterSet::instance()->show();
}


void MainInterface::on_SQLPushButton_S_clicked()
{
//获取当账户类型
extern UserInfo currentUserInfo;//存储当前用户信息
if(currentUserInfo.userType==1)
{
UserMysqlS::instance()->setTabelViewEnabled(0,true);
}
else
{

UserMysqlS::instance()->setTabelViewEnabled(0,false);

}
UserMysqlS::instance()->disPlayTabel(1);
UserMysqlS::instance()->setCurrentTabelView(1);
UserMysqlS::instance()->show();
}


void MainInterface::on_ModSim32PushButton_S_clicked()
{
 //启动Modsim32程序
 if(!ModSim32Status)
 {
     ModSim32Status=true;
     launchModSim32();
     //设置ModSim32按钮为打开状态
     setModSim32PushButton(ModSim32Status);
 }
 else
 {
      ModSim32Status=false;
      closeModSim32();
      setModSim32PushButton(ModSim32Status);

 }
}

